package com.googlecode.cswish.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DebugUtil {

	private static final Log logger = LogFactory.getLog(DebugUtil.class);
	
	private final static ThreadLocal<Integer> threadId = new ThreadLocal<Integer>();
	
	private static int id;
	
	private static synchronized int newId() {
		return ++id;
	}
	
	public static void traceNew(String msg) {
		threadId.set(newId());
		logger.debug(threadId.get() + "," + msg);
	}
	
	public static void trace(String msg) {
		Integer curId = threadId.get();
		if (curId == null) {
			curId = newId();
			threadId.set(curId);
		}
		logger.debug(curId + "," + msg);
	}
}
